home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / Source / InspectorTest.cp < prev    next >
Encoding:
Text File  |  1998-06-12  |  1.2 KB  |  77 lines  |  [TEXT/CWIE]

  1. #include "InspectorTest.h"
  2. #include "SmartPtr.h"
  3.  
  4. DefineClass1Base(ClassA, TObject);
  5. DefineClass1Base(ClassB, ClassA);
  6. DefineClass2Base(ClassC, ClassA, TObject);
  7. DefineClass2Base(ClassD, ClassB, ClassC);
  8.  
  9.     static SmartPtr<ClassA> foo(ClassA& a)
  10.     {
  11.         a.fVariableA = 7;
  12.         
  13.         return &a;
  14.     }
  15.  
  16.  class Foo
  17.  {
  18.  public:
  19.  
  20.     static ObjectPtr TestFunc(TObject& foo)
  21.     {
  22.         return &foo;    // try to set a breakpoint here....
  23.     }
  24.     
  25.   };
  26.  
  27.     static void unexpected_called()
  28.     {
  29.         DebugStr("\pSomeone called unexpected() - you're hosed.");
  30.     }
  31.  
  32.     static void terminate_called()
  33.     {
  34.         DebugStr("\pSomeone called terminate() - you're hosed.");
  35.     }
  36.  
  37. void InspectorTest(void)
  38. {
  39. Debugger();
  40.  
  41.     try
  42.     {
  43.         ObjectPtr            o(new ClassA(7));
  44.         SmartPtr<ClassC>    c(new ClassC(9));
  45.         SmartPtr<ClassB>    b(new ClassD(11,22,33));
  46.         SmartPtr<ClassD>    d(new ClassD(11,22,33));
  47.         
  48.         SmartPtr<TObjectList> list = new TObjectList;
  49.         
  50.         o = Foo::TestFunc(*o);
  51.         
  52.         list->AppendObject(o);
  53.         list->AppendObject(b);
  54.  
  55.         {
  56.             SmartPtr<ClassA> a = foo(*c);
  57.             
  58.             list->AppendObject(a);
  59.  
  60.             Debugger();
  61.         }
  62.         
  63.         list->AppendObject(d);
  64.         
  65.         Debugger();
  66.         
  67.         FailOSErr(69);    // <-- step over to hose CW
  68.     }
  69.     catch(...)
  70.     {
  71.         DebugStr("\pException caught");
  72.     }
  73.     
  74.     Debugger();
  75. }
  76.  
  77.